package com.briup.bms.web.controller;

import com.briup.bms.bean.SCustomer;
import com.briup.bms.common.utils.Result;
import com.briup.bms.service.SCustomerService;
import com.briup.bms.service.SOrderService;
import com.briup.bms.web.vm.OrderVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author: Paocha
 * @date: 2021-11-23-16:59
 */
@Api(tags = "订单信息服务")
@RestController
@RequestMapping("/order")
public class OrderController {

    private final SOrderService orderService;


    public OrderController(SOrderService orderService) {
        this.orderService = orderService;
    }

    @ApiOperation(value = "按条件分页显示客户信息")
    @GetMapping("/by/condition")
    public Result<PageInfo<OrderVo>> findByCondition(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize,
            String name) {

        return Result.success(orderService.findByConditon(
                pageNum, pageSize, name));
    }

    @GetMapping()
    public Result<PageInfo<OrderVo>> findByPageHelper(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {

        return Result.success(orderService.findByPageHelper(
                pageNum, pageSize));
    }

    @PostMapping
    public Result<String> saveOrUpdate(@RequestBody OrderVo orderVo) {
        //业务处理
        orderService.saveOrUpdate(orderVo);
        return Result.success("操作成功！");
    }

    @DeleteMapping("/{OrderId}")
    public Result<String> deleteCustomer(@PathVariable("OrderId") Integer OrderId) {
        orderService.deleteOrder(OrderId);
        return Result.success("删除"+OrderId+"成功");
    }
    @DeleteMapping("/batchDelete}")
    public Result<String> batchDeleteCustomer(Integer[] OrderIds) {
        orderService.batchDeleteOrder(OrderIds);
        return Result.success("删除"+ Arrays.toString(OrderIds) +"成功");
    }

}
